package com.markus.code.exam.laohujituan;

import com.sun.javafx.binding.StringFormatter;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/6 16:46
 * todo:
 */
public class Main1 {
    public boolean isPalindrome (String str) {
        // write code here
        return process(str);
    }
    private boolean process(String s){
        char []ch = s.toCharArray();
        int left = 0;
        int right = ch.length-1;
        while(left < right){
            while (!isZiMuOrNumber(ch[left])){
                left++;
            }
            while(!isZiMuOrNumber(ch[right])){
                right--;
            }
            if (getCh(ch[left]) != getCh(ch[right])){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
    private boolean isZiMuOrNumber(char ch){
        if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')){
            return true;
        }
        return false;
    }
    private char getCh(char ch){
        if (ch >= 'A' && ch <= 'Z'){
            return (char) (ch+32);
        }else {
            return ch;
        }
    }

    public static void main(String[] args) {
        String str = "A man, a plan, a canal: Panama";
        Main1 demo = new Main1();
        System.out.println(demo.isPalindrome(str));
    }
}
